#!/usr/bin/env node

const exp = process.argv[2];

if(typeof exp === 'undefined' || exp === '--help' || exp === '-h'){
  help();
}else{
  calc();
}

function help(){
  console.log('\
      usage: cmd-name [OPTION] [expression]\n\
      evaluate the expression.\n\
      \n\
      Mandatory arguments to long options are mandatory for short options too.\n\
      -h, --help output help information and exit')
}
function calc(){
  try{
    console.log(`${exp}=${eval(exp)}`);
  }catch(e){
    console.err(`${exp} 不是合法的数学表达式！`);
  }
}
